<?php
/**
 * Project: ShopWorx- making your life easier
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * @Author Chris
 * @File Auth.class.php
 * @Version 1.0.0
 * @Copyright 2008 Shopworx (c)
 * @Year 2008
 * @access Public
 */

include_once DEBUG_CLASS;

/**
 * Authentication Layer.
 *
 *@package Auth
 */

class Auth
{
    function Auth()
    {
        global $db_url;
        $this->status = false;
        $this->db_url = $db_url;

    }

    function Authenticate($email = null, $passwd = null)
    {
        $db = new DBAL($this->db_url);
        $this->email = $email;
        $this->passwd = $passwd;

        $query = "SELECT UID, PASSWORD FROM users WHERE EMAIL = '" . $this->email . "' AND ACTIVE = 1";
        $result = $db->query($query);

        if ($result != null) {
            $row = $result->fetchRow();

            if (md5($this->passwd) == $row->PASSWORD) {
                $this->status = true;
                $this->user_id = $row->UID;
            } else {
                $this->status = false;
            }


        }
        $db->disconnect();
        return $this->status;
    }
    
    function getUID()
    {
		return $this->user_id;
    }
}
